package com.elysia.adminservice.controller;

import com.elysia.adminservice.domain.dto.GameNewsDTO;
import com.elysia.adminservice.domain.vo.GameNewsVO;
import com.elysia.adminservice.feign.NewsFeignClient;
import com.elysia.adminservice.result.Result;
import com.elysia.adminservice.service.impl.IGameNewsServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/game-news")
@RequiredArgsConstructor
@Slf4j
public class GameNewsController {
    private final IGameNewsServiceImpl gameNewsService;
    private final NewsFeignClient newsFeignClient;
    @PostMapping("/upload-token")
    public Result<String> getFileUploadToken(@RequestHeader("X-seacross-id") Long userId) {
        log.info("用户{}获取上传token", userId);
        return gameNewsService.getFileUploadToken(userId);
    }
    @PostMapping
    public Result<GameNewsVO> addGameNews(@RequestBody GameNewsDTO gameNewsDTO){
        log.info("添加公告{}", gameNewsDTO);
        return newsFeignClient.addGameNews(gameNewsDTO);
    }
    @GetMapping
    public Result<List<GameNewsVO>> getAllGameNews(){
        log.info("获取所有公告");
        return newsFeignClient.getAllGameNews();
    }
    @PutMapping("/{id}")
    public Result<GameNewsVO> updateGameNews(@PathVariable Long id, @RequestBody GameNewsDTO gameNewsDTO){
        log.info("更新公告{}:{}", id, gameNewsDTO);
        return newsFeignClient.updateGameNews(id , gameNewsDTO);
    }
}
